<template>
	<!-- <view class="content page1">
		<view class="title"></view>
	</view> -->
	<view></view>
</template>

<script>
	
	export default {
		data() {
			return {
				touxiang:'',
				nickName:'',
				code:'',
				userInfo:{}
			}
		},
		onShow() {
			this.getUserInfoRes()
			
		},
		methods: {
			getUserInfoRes(){
				uni.showLoading({
					title:'正在加载数据',
					mask:true
				})
				var ua = navigator.userAgent.toLowerCase();
				if(ua.match(/MicroMessenger/i)=="micromessenger") {
					let code = GetQueryString("code")
					console.log('code',code); //哪这个code去服务端换userInfo
					this.code = code
					uniCloud.callFunction({
						name:'getUserInfo',
						data:{code:this.code}
					}).then((res)=>{
						console.log(res)
						let userInfo = res.result.data
						// uni.setStorageSync('userInfo',res.result.data)
						uniCloud.callFunction({
							name:'saveUser',
							data:userInfo
						}).then((res1)=>{
							console.log(res1)
							uni.hideLoading()
							
								uni.setStorageSync('userInfo',res1.result.data[0])
								uni.setStorageSync('openID',res1.result.data[0].openid)
								uni.redirectTo({
									url:'../language/language'
								})
							
							
						})
					}).catch((res)=>{
						uni.hideLoading()
						console.log(res)
					})
				} else {
					uni.hideLoading()
					console.log('不在微信里面不能微信登录');
					return false;
				}
					
				function GetQueryString(name)//获取参数
				{
				    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
				    var r = window.location.search.substr(1).match(reg);	//search,查询？后面的参数，并匹配正则
				    if(r!=null)return  unescape(r[2]); return null;
				}
			}
		}
	}
</script>

<style>
.linfeng{
	font-family: 'zhenhao';
	font-size: 60rpx;
}
</style>
